package com.example.admin.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class FragmentDiscover extends Fragment {
    private List<Imge> imgeList = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.discover,container,false);
        initImge();
        ImgeAdapter adapter = new ImgeAdapter(getContext(), R.layout.imge_main, imgeList);
        ListView listView = (ListView) view.findViewById(R.id.list_view_discover);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Imge imge = imgeList.get(position);
                Intent intent = new Intent(getContext(), MgsMain.class);
                intent.putExtra("name", imge.getName());
                startActivity(intent);
            }
        });
        return view;
    }
    private void initImge() {
        imgeList.add(new Imge("moments", R.drawable.moments));
        imgeList.add(new Imge("scan qr code", R.drawable.scan_qr_code));
        imgeList.add(new Imge("shake", R.drawable.shake));
        imgeList.add(new Imge("have_a_look", R.drawable.have_a_look));
        imgeList.add(new Imge("search", R.drawable.search));
        imgeList.add(new Imge("people", R.drawable.people));
        imgeList.add(new Imge("small_routine", R.drawable.small_routine));
    }
}